<!DOCTYPE HTML>
<html lang="en" >
    <!-- Start book 项目实训课程讲义 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>表单的定义 | 项目实训课程讲义</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="BigCat">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../data/form/form.html" />
    
    
    <link rel="prev" href="../../data/form/index.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="1.1"
        data-chapter-title="表单的定义"
        data-filepath="data/form/form_define.md"
        data-basepath="../.."
        data-revision="Fri Apr 26 2019 21:51:37 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        博学谷在线
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="data/form/index.html">
            
                
                    <a href="../../data/form/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        Django表单系统
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.1" data-path="data/form/form_define.html">
            
                
                    <a href="../../data/form/form_define.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        表单的定义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="data/form/form.html">
            
                
                    <a href="../../data/form/form.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        表单的渲染
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="data/form/form_valid.html">
            
                
                    <a href="../../data/form/form_valid.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        表单数据的验证
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="data/form/Captcha.html">
            
                
                    <a href="../../data/form/Captcha.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        验证码模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="data/path.html">
            
                
                    <a href="../../data/path.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        环境搭建
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="data/data.html">
            
                
                    <a href="../../data/data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        数据录入
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4" data-path="data/index.html">
            
                
                    <a href="../../data/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        首页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5" data-path="data/register.html">
            
                
                    <a href="../../data/register.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        用户注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6" data-path="data/login.html">
            
                
                    <a href="../../data/login.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        用户登录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7" data-path="data/forget_pwd.html">
            
                
                    <a href="../../data/forget_pwd.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        忘记密码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="data/change_pwd.html">
            
                
                    <a href="../../data/change_pwd.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        修改密码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="data/user/user_info.html">
            
                
                    <a href="../../data/user/user_info.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        用户中心
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="data/user/user_class.html">
            
                
                    <a href="../../data/user/user_class.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        我的课程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="data/user/user_collect.html">
            
                
                    <a href="../../data/user/user_collect.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        我的收藏
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="data/user/user_msg.html">
            
                
                    <a href="../../data/user/user_msg.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.3.</b>
                        
                        我的消息
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >项目实训课程讲义</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5B9A;&#x4E49;&#x8868;&#x5355;">&#x5B9A;&#x4E49;&#x8868;&#x5355;</h1>
<h2 id="1--&#x5B9A;&#x4E49;&#x65B9;&#x6CD5;">1.  &#x5B9A;&#x4E49;&#x65B9;&#x6CD5;</h2>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x5DF2;&#x6709;&#x4E86;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x6A21;&#x578B;&#x7C7B;User</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.db <span class="hljs-keyword">import</span> models
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span><span class="hljs-params">(models.Model)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
        &#x7528;&#x6237;&#x6A21;&#x578B;&#x7C7B;
    &quot;&quot;&quot;</span>
    username = models.CharField(max_length=<span class="hljs-number">20</span>, unique=<span class="hljs-keyword">True</span>,verbose_name=<span class="hljs-string">&apos;&#x7528;&#x6237;&#x540D;&apos;</span>)
    password = models.CharField(max_length=<span class="hljs-number">20</span>,verbose_name=<span class="hljs-string">&apos;&#x5BC6;&#x7801;&apos;</span>)
    mobile = models.CharField(max_length=<span class="hljs-number">11</span>, unique=<span class="hljs-keyword">True</span>,verbose_name=<span class="hljs-string">&apos;&#x624B;&#x673A;&#x53F7;&apos;</span>)
</code></pre>
<p>&#x6211;&#x4EEC;&#x60F3;&#x5728;&#x6CE8;&#x518C;&#x65F6;&#x751F;&#x6210;&#x548C;&#x7528;&#x6237;&#x5B57;&#x6BB5;&#x76F8;&#x5173;&#x7684;&#x6CE8;&#x518C;&#x8868;&#x5355;&#xFF0C;&#x8FD9;&#x662F;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x73B0;&#x5728;user&#x5E94;&#x7528;&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;forms&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x5B9A;&#x4E49;&#x7528;&#x6237;&#x6CE8;&#x518C;&#x8868;&#x5355;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django <span class="hljs-keyword">import</span> forms

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RegisterForm</span><span class="hljs-params">(forms.Form)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
        &#x7528;&#x6237;&#x6CE8;&#x518C;&#x8868;&#x5355;
    &quot;&quot;&quot;</span>
    username = forms.CharField(max_length=<span class="hljs-number">20</span>, min_length=<span class="hljs-number">5</span>, required=<span class="hljs-keyword">True</span>,label=<span class="hljs-string">&apos;&#x7528;&#x6237;&#x540D;&apos;</span>)
    password = forms.CharField(max_length=<span class="hljs-number">20</span>, min_length=<span class="hljs-number">8</span>, required=<span class="hljs-keyword">True</span>,label=<span class="hljs-string">&apos;&#x5BC6;&#x7801;&apos;</span>)
    mobile = forms.CharField(max_length=<span class="hljs-number">11</span>, min_length=<span class="hljs-number">11</span>,required=<span class="hljs-keyword">True</span>,label=<span class="hljs-string">&apos;&#x624B;&#x673A;&#x53F7;&apos;</span>)
</code></pre>
<h2 id="2--&#x8868;&#x5355;&#x5B9A;&#x4E49;&#x65F6;&#x7684;&#x5B57;&#x6BB5;&#x4E0E;&#x9009;&#x9879;">2.  &#x8868;&#x5355;&#x5B9A;&#x4E49;&#x65F6;&#x7684;&#x5B57;&#x6BB5;&#x4E0E;&#x9009;&#x9879;</h2>
<p><strong>&#x5E38;&#x7528;&#x5B57;&#x6BB5;&#x7C7B;&#x578B;</strong>&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x5B57;&#x6BB5;</th>
<th>&#x5B57;&#x6BB5;&#x6784;&#x9020;&#x65B9;&#x5F0F;</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>BooleanField</strong></td>
<td>BooleanField()</td>
</tr>
<tr>
<td><strong>NullBooleanField</strong></td>
<td>NullBooleanField()</td>
</tr>
<tr>
<td><strong>CharField</strong></td>
<td>CharField(max_length=None, min_length=None, allow_blank=False, trim_whitespace=True)</td>
</tr>
<tr>
<td><strong>EmailField</strong></td>
<td>EmailField(max_length=None, min_length=None, allow_blank=False)</td>
</tr>
<tr>
<td><strong>RegexField</strong></td>
<td>RegexField(regex, max_length=None, min_length=None, allow_blank=False)</td>
</tr>
<tr>
<td><strong>SlugField</strong></td>
<td>SlugField(max<em>length=50, min_length=None, allow_blank=False) <br> &#x6B63;&#x5219;&#x5B57;&#x6BB5;&#xFF0C;&#x9A8C;&#x8BC1;&#x6B63;&#x5219;&#x6A21;&#x5F0F; [a-zA-Z0-9</em>-]+</td>
</tr>
<tr>
<td><strong>URLField</strong></td>
<td>URLField(max_length=200, min_length=None, allow_blank=False)</td>
</tr>
<tr>
<td><strong>UUIDField</strong></td>
<td>UUIDField(format=&apos;hex_verbose&apos;)    <br>  format: <br>1)   <code>&apos;hex_verbose&apos;</code> &#x5982;<code>&quot;5ce0e9a5-5ffa-654b-cee0-1238041fb31a&quot;</code> <br>2&#xFF09; <code>&apos;hex&apos;</code>  &#x5982; <code>&quot;5ce0e9a55ffa654bcee01238041fb31a&quot;</code> <br>3&#xFF09;<code>&apos;int&apos;</code> - &#x5982;: <code>&quot;123456789012312313134124512351145145114&quot;</code>  <br>4&#xFF09;<code>&apos;urn&apos;</code> &#x5982;: <code>&quot;urn:uuid:5ce0e9a5-5ffa-654b-cee0-1238041fb31a&quot;</code></td>
</tr>
<tr>
<td><strong>IPAddressField</strong></td>
<td>IPAddressField(protocol=&apos;both&apos;, unpack_ipv4=False, **options)</td>
</tr>
<tr>
<td><strong>IntegerField</strong></td>
<td>IntegerField(max_value=None, min_value=None)</td>
</tr>
<tr>
<td><strong>FloatField</strong></td>
<td>FloatField(max_value=None, min_value=None)</td>
</tr>
<tr>
<td><strong>DecimalField</strong></td>
<td>DecimalField(max_digits, decimal_places, coerce_to_string=None, max_value=None, min_value=None)<br>max_digits:  &#x6700;&#x591A;&#x4F4D;&#x6570;<br>decimal_palces:  &#x5C0F;&#x6570;&#x70B9;&#x4F4D;&#x7F6E;</td>
</tr>
<tr>
<td><strong>DateTimeField</strong></td>
<td>DateTimeField(format=api_settings.DATETIME_FORMAT, input_formats=None)</td>
</tr>
<tr>
<td><strong>DateField</strong></td>
<td>DateField(format=api_settings.DATE_FORMAT, input_formats=None)</td>
</tr>
<tr>
<td><strong>TimeField</strong></td>
<td>TimeField(format=api_settings.TIME_FORMAT, input_formats=None)</td>
</tr>
<tr>
<td><strong>DurationField</strong></td>
<td>DurationField()</td>
</tr>
<tr>
<td><strong>ChoiceField</strong></td>
<td>ChoiceField(choices)<br>choices&#x4E0E;Django&#x7684;&#x7528;&#x6CD5;&#x76F8;&#x540C;</td>
</tr>
<tr>
<td><strong>MultipleChoiceField</strong></td>
<td>MultipleChoiceField(choices)</td>
</tr>
<tr>
<td><strong>FileField</strong></td>
<td>FileField(max_length=None, allow_empty_file=False, use_url=UPLOADED_FILES_USE_URL)</td>
</tr>
<tr>
<td><strong>ImageField</strong></td>
<td>ImageField(max_length=None, allow_empty_file=False, use_url=UPLOADED_FILES_USE_URL)</td>
</tr>
<tr>
<td><strong>ListField</strong></td>
<td>ListField(child=<A_FIELD_INSTANCE>, min_length=None, max_length=None)</A_FIELD_INSTANCE></td>
</tr>
<tr>
<td><strong>DictField</strong></td>
<td>DictField(child=<A_FIELD_INSTANCE>)</A_FIELD_INSTANCE></td>
</tr>
</tbody>
</table>
<p><strong>&#x9009;&#x9879;&#x53C2;&#x6570;&#xFF1A;</strong></p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;&#x540D;&#x79F0;</th>
<th>&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>max_length</strong></td>
<td>&#x6700;&#x5927;&#x957F;&#x5EA6;</td>
</tr>
<tr>
<td><strong>min_lenght</strong></td>
<td>&#x6700;&#x5C0F;&#x957F;&#x5EA6;</td>
</tr>
<tr>
<td><strong>allow_blank</strong></td>
<td>&#x662F;&#x5426;&#x5141;&#x8BB8;&#x4E3A;&#x7A7A;</td>
</tr>
<tr>
<td><strong>trim_whitespace</strong></td>
<td>&#x662F;&#x5426;&#x622A;&#x65AD;&#x7A7A;&#x767D;&#x5B57;&#x7B26;</td>
</tr>
<tr>
<td><strong>max_value</strong></td>
<td>&#x6700;&#x5C0F;&#x503C;</td>
</tr>
<tr>
<td><strong>min_value</strong></td>
<td>&#x6700;&#x5927;&#x503C;</td>
</tr>
</tbody>
</table>
<h4 id="&#x901A;&#x7528;&#x53C2;&#x6570;&#xFF1A;">&#x901A;&#x7528;&#x53C2;&#x6570;&#xFF1A;</h4>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;&#x540D;&#x79F0;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>required</strong></td>
<td>&#x8868;&#x660E;&#x8BE5;&#x5B57;&#x6BB5;&#x5728;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x65F6;&#x5FC5;&#x987B;&#x8F93;&#x5165;&#xFF0C;&#x9ED8;&#x8BA4;True</td>
</tr>
<tr>
<td><strong>default</strong></td>
<td>&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x9ED8;&#x8BA4;&#x503C;</td>
</tr>
<tr>
<td><strong>allow_null</strong></td>
<td>&#x8868;&#x660E;&#x8BE5;&#x5B57;&#x6BB5;&#x662F;&#x5426;&#x5141;&#x8BB8;&#x4F20;&#x5165;None&#xFF0C;&#x9ED8;&#x8BA4;False</td>
</tr>
<tr>
<td><strong>validators</strong></td>
<td>&#x8BE5;&#x5B57;&#x6BB5;&#x4F7F;&#x7528;&#x7684;&#x9A8C;&#x8BC1;&#x5668;</td>
</tr>
<tr>
<td><strong>error_messages</strong></td>
<td>&#x5305;&#x542B;&#x9519;&#x8BEF;&#x7F16;&#x53F7;&#x4E0E;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x7684;&#x5B57;&#x5178;</td>
</tr>
<tr>
<td><strong>label</strong></td>
<td>&#x7528;&#x4E8E;HTML&#x5C55;&#x793A;&#x9875;&#x9762;&#x65F6;&#xFF0C;&#x663E;&#x793A;&#x7684;&#x5B57;&#x6BB5;&#x540D;&#x79F0;</td>
</tr>
<tr>
<td><strong>help_text</strong></td>
<td>&#x7528;&#x4E8E;HTML&#x5C55;&#x793A;&#x9875;&#x9762;&#x65F6;&#xFF0C;&#x663E;&#x793A;&#x7684;&#x5B57;&#x6BB5;&#x5E2E;&#x52A9;&#x63D0;&#x793A;&#x4FE1;&#x606F;</td>
</tr>
</tbody>
</table>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../data/form/index.html" class="navigation navigation-prev " aria-label="Previous page: Django表单系统"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../data/form/form.html" class="navigation navigation-next " aria-label="Next page: 表单的渲染"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"disqus":{"shortName":"gitbookuse"},"github":{"url":"https://github.com/dododream"},"search-pro":{"cutWordLib":"nodejieba","defineWord":["gitbook-use"]},"sharing":{"weibo":true,"facebook":true,"twitter":true,"google":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"tbfed-pagefooter":{"copyright":"Copyright © ITCast","modify_label":"「Revision Time:","modify_format":"YYYY-MM-DD HH:mm:ss」"},"baidu":{"token":"ff100361cdce95dd4c8fb96b4009f7bc"},"sitemap":{"hostname":"http://www.treenewbee.top"},"donate":{"wechat":"http://weixin.png","alipay":"http://alipay.png","title":"","button":"赏","alipayText":"支付宝打赏","wechatText":"微信打赏"},"edit-link":{"base":"https://github.com/dododream/edit","label":"Edit This Page"},"splitter":{},"toggle-chapters":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book 项目实训课程讲义 -->
</html>
